/*
 * Created by JFormDesigner on Mon Jun 14 22:04:44 CST 2021
 */

package com.J1ay.carsys.gui.Emp.Dialog;

import java.awt.event.*;

import com.J1ay.carsys.gui.tishi.Success;
import com.J1ay.carsys.gui.tishi.Warning;
import com.J1ay.carsys.pojo.Bower;
import com.J1ay.carsys.pojo.Emp;
import com.J1ay.carsys.pojo.Result;
import com.J1ay.carsys.service.EmpService;
import com.J1ay.carsys.service.Impl.EmpServiceImpl;

import java.awt.*;
import javax.swing.*;
import javax.swing.GroupLayout;

/**
 * @author Brainrain
 */
public class CheckDialog extends JDialog {
    String UId;
    int EmpId;
    EmpService empService = new EmpServiceImpl();
    Bower nowBower;
    public CheckDialog(Window owner, Bower bower, int empId) {
        super(owner);
        initComponents();
        this.label2.setText("您目前选择的用户名为："+bower.getBname());
        UId = bower.getUId();
        nowBower = bower;
        EmpId = empId;
    }
    public void start() {
        this.setVisible(true);
    }

    private void button1ActionPerformed(ActionEvent e) {
        // TODO add your code here
        nowBower.setUId(UId);
        nowBower.setStatus(1);
        nowBower.setEmpId(EmpId);
        Result result = empService.checkBower(nowBower);
        if (200 == result.getStatus()){
            new Success(this,"审核通过成功!").start();
            this.dispose();
        }
        else{
            new Warning(this,result.getMsg()).start();
        }
    }

    private void button2ActionPerformed(ActionEvent e) {
        // TODO add your code here
        nowBower.setStatus(0);
        nowBower.setEmpId(EmpId);
        nowBower.setUId(UId);
        new Del1(this,nowBower).start();
        System.out.println(nowBower);

    }
    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        label1 = new JLabel();
        button1 = new JButton();
        button2 = new JButton();
        label2 = new JLabel();

        //======== this ========
        setTitle("\u5c0f\u6c7d\u8f66\u7ba1\u7406\u7cfb\u7edf");
        setResizable(false);
        Container contentPane = getContentPane();

        //---- label1 ----
        label1.setText("\u8bf7\u9009\u62e9\u60a8\u7684\u5ba1\u6838\u7ed3\u679c");

        //---- button1 ----
        button1.setText("\u901a\u8fc7");
        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                button1ActionPerformed(e);
            }
        });

        //---- button2 ----
        button2.setText("\u4e0d\u901a\u8fc7");
        button2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                button2ActionPerformed(e);
            }
        });

        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addGap(108, 108, 108)
                    .addGroup(contentPaneLayout.createParallelGroup()
                        .addComponent(label1, GroupLayout.DEFAULT_SIZE, 290, Short.MAX_VALUE)
                        .addGroup(contentPaneLayout.createSequentialGroup()
                            .addComponent(label2, GroupLayout.DEFAULT_SIZE, 275, Short.MAX_VALUE)
                            .addGap(15, 15, 15))
                        .addGroup(contentPaneLayout.createSequentialGroup()
                            .addComponent(button1)
                            .addGap(32, 32, 32)
                            .addComponent(button2)
                            .addContainerGap(106, Short.MAX_VALUE))))
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addGap(38, 38, 38)
                    .addComponent(label2, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(label1, GroupLayout.PREFERRED_SIZE, 42, GroupLayout.PREFERRED_SIZE)
                    .addGap(31, 31, 31)
                    .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(button1)
                        .addComponent(button2))
                    .addContainerGap(53, Short.MAX_VALUE))
        );
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JLabel label1;
    private JButton button1;
    private JButton button2;
    private JLabel label2;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
